package com.cn.dao;

import com.cn.entity.User;
import com.cn.util.DBUtil;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class Logindao {
    static ResultSet rs=null;
    static User user=null;
    public boolean isEdist(String phone){
        return queryUserByPhone(phone)!=null?true:false;
    }

    public static User queryUserByPhone(String phone) {
        String sql = "select * from user where phone=?";
        Object[] obj={phone};
        rs = DBUtil.query(sql,obj);
        try {
            if (rs.next()) {
                int id1 = rs.getInt("id");
                String name1 = rs.getString("name");
                String phone1 = rs.getString("phone");
                String pwd1 = rs.getString("password");
                user = new User(id1, name1, phone1, pwd1);
            }
            return user;
        } catch (SQLException e) {
            e.printStackTrace();
            return null;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }finally {
            DBUtil.closeAll(rs,DBUtil.pstm,DBUtil.conn);
        }
    }
}
